
***********************************;
** Output hedis2012.sas7bdat      *;
***********************************;

options ls=76 nofmterr;

libname raw '/data/Medicare_P01_2009/data/HEDIS/rawdata';
libname new '/data/Medicare_P01_2009/data/HEDIS/sasdata';


data sk00; set raw.sca_kaiser2012; 

     length hic_num $ 12;
     hic_num=substr(hic_number,1,12);
     drop hic_number lname fname county;
     rename hic_num=hic_number;

     length org_id $5; 
     org_id='HS524'; 

data nk00; set raw.nca_kaiser2012;

     length hic_number $ 12;
     hic_number=substr(c1,1,12);
     drop c1 c2 c3 c4;
     length org_id $5;
     org_id='HN524';

data kaiser; set sk00 nk00;

     proc sort; by hic_number;

data a001; set raw.hedis2012data;

     if cms_contract_number='H0524' ;

     proc sort; by hic_number;

data a01; merge kaiser(in=a) a001(in=b); by hic_number;

     if a and b;

data a02; set raw.hedis2012data;

     length org_id $5;

     org_id = cms_contract_number;

     if org_id = 'H0524' then delete;

data new.hedis2012s; set a01 a02;

     ** Invalid HIC number Indicators **;

     if substr(hic_number,2,11)=' ' or
        substr(hic_number,3,10)=' ' or 
        substr(hic_number,4,9) =' ' or
        substr(hic_number,5,8) =' ' then short_hic=1; else short_hic=0;

      if hic_number=' ' or
         hic_number='00000' or
         hic_number='000000' or
         hic_number='0000000' or
         hic_number='00000000' or
         hic_number='000000000' or
         hic_number='0000000000' or
         hic_number='00000000000' or
         hic_number='000000000000' or

         hic_number='99999' or
         hic_number='999999' or
         hic_number='9999999' or
         hic_number='99999999' or
         hic_number='999999999' or
         hic_number='9999999999' or
         hic_number='99999999999' or
         hic_number='999999999999' or  
         hic_number='Error' or
         hic_number='NA' or 
         hic_number='UNKNOWN' then invalid_hic=1; else invalid_hic=0; 

       **  Exclude Invalid Cases  **;

       if short_hic=1 or invalid_hic=1 then delete;  /** Excluded 74 short and 213 invalid HIC numbers **/

       totmonth = m_months;

       drop gender short_hic invalid_hic  PERCENT COUNT;

       proc sort; by hic_number descending m_months;  

       proc sort nodupkey; by hic_number;  /** a very small pct cases with multiple plan enrollment removed <0.01% if any **/

endsas;

